import {query} from '../servers';
import FROMURL from '../exportURL';
import router from '../router/index';
export default {
    modules: {
        xiaoma: {
            namespaced: true,
            //初始数据
            state: {
                isloginState:false,
            },
            //数据过滤
            getters: {
                //清除脏数据
                deleteVal(state){
                    state = !state.isloginState;
                }
            },
            //同步函数
            mutations: {
                save(state, action){
                    console.log(action);
                    action.map(val=>{state[val[0]] = val[1]});
                },
            },
            //异步函数
            actions: {
                async login(context, val){
                    const {data} = await query(FROMURL.login,{user:val.userName,pwd:val.pwd},'post','obj');
                    console.log('数据:',data);
                    if(data.title=="登录成功"){
                        context.commit('save',[['isloginState',true]]);
                        router.push({name:'home'});//跳转路由
                    }else {
                        context.commit('save',[['isloginState',true]]);
                    }
                },
                deleteVal(context,val){
                    context.commit('save',[['isloginState',false]]);
                }
            },
            //组件嵌套
            modules: []
        }
    }
}